package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

//@Controller
public class EmployeeController {
/*

    @RequestMapping(value = "/employees" ,method = RequestMethod.GET)
    @ResponseBody
    public List<Employee> list(){
        List<Employee> list = Arrays.asList(new Employee(1L,18,"dasha"),
        new Employee(2L,16,"ersha"));
        return list;
    }

    @RequestMapping(value = "/employees",method = RequestMethod.POST)
    @ResponseBody
    public Employee save(Employee employee){
        employee.setId(3L);
        return employee;
    }

    @RequestMapping(value = "/employees" , method = RequestMethod.PUT)
    @ResponseBody
    public Employee update (Employee employee){
        employee.setName(employee.getName() + "hahaha");
        return employee;
    }

    @RequestMapping(value = "/employees",method = RequestMethod.DELETE)
    @ResponseBody
    public JsonResult delete(Long id){
        return JsonResult.success();
    }


    */
/**
     * 查询指定id的员工数据
     * 问题:  员工列表接口(查询多个)员工明细接口(查单个)
     * 使用资源路径都是 / employees 请求方式都是get ,此时StringMvc就无法进行唯一识别
     * 问 : 此时怎么办?
     * 解决方案 : 使用参数路径方式,
     *
     * 参数路径 : 将请求接口的参数作为路径的一部分
     * 比如:   /employees/{id}
     * 其中:   /employees/{id} 参数路径 ----- {id}路径参数
     * 参数路径访问方式: http://localhost:8080/employees/21 其中21就是路径参数
     *
     * 接口如何获取路径参数呢
     * 使用@PathVariable 注解
     * 作用:从参数路径(url)上将路径参数解析,并赋值接口形式参数
     * 如果形式参数变量名与路径参数变量名不一致使用
     * @PathVariable("变量名") 明确指定
     *
     * 参数路径方式优缺点
     * 1>可以隐藏参数,安全性相对高
     * 2>参数路径参数不能太多 (5个左右)
     *//*

    @RequestMapping(value = "/employees/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Employee detail(@PathVariable Long id){
        return new Employee(id,18,"dasha");
    }
*/

}
